package com.yxdj.feedback.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yxdj.common.core.web.controller.BaseController;
import com.yxdj.common.core.web.domain.AjaxResult;
import com.yxdj.common.core.web.page.TableDataInfo;
import com.yxdj.common.log.annotation.Log;
import com.yxdj.common.log.enums.BusinessType;
import com.yxdj.common.security.utils.SecurityUtils;
import com.yxdj.feedback.domain.UserComplaint;
import com.yxdj.feedback.service.UserComplaintService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 用户投诉管理
 */
@Tag(name = "用户投诉管理")
@RestController
@RequestMapping("/complaint")
public class UserComplaintController extends BaseController {

    @Autowired
    private UserComplaintService userComplaintService;


    /**
     * 分页获取用户投诉列表
     */
    @Operation(summary = "分页获取用户投诉列表")
    @GetMapping("/list")
    public TableDataInfo list(@RequestParam(name = "status",required = false) Integer status) {
        startPage();
        List<UserComplaint> list = userComplaintService.list(new LambdaQueryWrapper<UserComplaint>().eq(status != null, UserComplaint::getStatus, status));
        return getDataTable(list);
    }

    /**
     * 获取用户投诉详细信息
     */
    @Operation(summary = "获取用户投诉详细信息")
    @GetMapping(value = "/getById/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id) {
        //获取用户投诉详细信息
        UserComplaint userComplaint  = userComplaintService.getUserComplainDetailById(id);
        return success(userComplaint);
    }

    /**
     * 新增用户投诉
     */
    @Operation(summary = "新增用户投诉")
    @Log(title = "用户投诉管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UserComplaint userComplaint) {
        return toAjax(userComplaintService.save(userComplaint));
    }

    /**
     * 处理用户投诉
     */
    @Operation(summary = "处理用户投诉")
    @Log(title = "用户投诉管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UserComplaint userComplaint) {
        userComplaint.setHandlerName(SecurityUtils.getUsername());
        return toAjax(userComplaintService.updateById(userComplaint));
    }

}
